
def group_by(list, fun):
    group_list = {}
    for item in list:
        key = fun(item)
        c_list = group_list.get(key, [])
        c_list.append(item)
        group_list[key] = c_list

    return group_list
